package cn.tedu.tickets;
/*需求:设计多线程编程模型,4个窗口共计售票100张
 * 本方案使用多线程的实现方案2:implements Runnable*/
public class TestRunnable {
    public static void main(String[] args) {

        TicketRunnable targer = new TicketRunnable();
        Thread t1 = new Thread(targer);
        Thread t2 = new Thread(targer);
        Thread t3 = new Thread(targer);
        Thread t4 = new Thread(targer);
        t1.start();
        t2.start();
        t3.start();
        t4.start();
    }
}
class TicketRunnable implements Runnable{
    int tickets = 100;
    @Override
    public void run() {
        while (true){
            try {
                Thread.sleep(10);//让当前线程休眠
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName()+"="+tickets--);
            if (tickets<0)break;
        }
    }
}